/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_handler
 * FILE       : FindOddEvenProcessHandler.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Mar 27, 2012  MyCodeTalks			       Created
 */

package net.lwf.handler.math.number;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.lwf.entity.QuestionInfo;
import net.lwf.number.util.NumberFormatter;
import net.lwf.number.util.RandomNumberGenerator;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;

import lwf.handler.IProcessHandler;
import lwf.handler.ProcessHandler;
import lwf.handler.entities.RadioData;
import lwf.handler.helper.DisplayFormatter;

public class FindOddEvenProcessHandler extends ProcessHandler implements IProcessHandler {
	
	private static final String ODD = "odd";
	private static final String EVEN = "even";

	public DisplayFormatter getDisplayFormatter() {
		
		return null;
	}

	public String getQuestionDesc() {
		
		return null;
	}

	@Override
	public QuestionInfo generateSingle() {
		return this.generateSingle(false);
	}

	@Override
	public List<QuestionInfo> generateMultiple() {
		List<QuestionInfo> questions = new ArrayList<QuestionInfo>();
		int nQuestions = getRows() * getColumns();
		for(int i=0; i<nQuestions; i++) {
			QuestionInfo question = generateSingle(true);
			question.setQuestionNumber(i+1);
			questions.add(question);
		}
		return questions;
	}

	@Override
	public void getContent(Document document) throws DocumentException {
		
		
	}

	@Override
	public int getRows() {
		
		return 0;
	}

	@Override
	public int getColumns() {
		
		return 0;
	}

	@Override
	public boolean isPortrait() {
		
		return false;
	}

	@Override
	public String getPdfInstructionalText() {
		
		return null;
	}

	@Override
	public String getPdfNote() {
		
		return null;
	}
	
	private QuestionInfo generateSingle(boolean isMultiple) {
		QuestionInfo qinfo = new QuestionInfo();
		String answer = ODD;
		int digitsreqd = RandomNumberGenerator.generate(1, 5);
		int number = RandomNumberGenerator.generate(digitsreqd);
		qinfo.setQuestion(NumberFormatter.format(String.valueOf(number)));
		if(number%2 == 0) {
			answer = EVEN;
		}
		setData1(String.valueOf(number));
		qinfo.setAnswer(answer);
		
		if(!isMultiple) {
			qinfo.setRadioAnswerChoices(getRadioAnswers());
			qinfo.setPlaceHolder("Identify the following number as even or odd number");
		}
		
		return qinfo;
	}
	
	private List<RadioData> getRadioAnswers() {
		List<RadioData> rdata = new ArrayList<RadioData>();
		rdata.add(new RadioData(ODD, ODD));
		rdata.add(new RadioData(EVEN, EVEN));		
		Collections.shuffle(rdata);
		return rdata;
	}

} //FindOddEvenProcessHandler
